package fristphase.day9_04.submarinegametest01;

import javax.swing.*;
import java.awt.*;
import java.util.Random;

public abstract class SeaObject {
    public static final int DEAD = 0;
    public static final int LIVE = 1;
    protected int state = LIVE;


    protected int width,height,x,y,speed,index;
    protected String name;

    //潜艇的超类构造方法
    public SeaObject(int width,int height,int index,String name){
        this.width = width;
        this.height = height;
        this.index = index;
        this.name = name;
        x = width;
        Random random = new Random();
        y = random.nextInt(459-height-150+1)+150;
        speed = random.nextInt(3)+1;
    }

    //战斗船，水雷，炸弹的超类构造函数
    public SeaObject(int width,int height,int x,int y,int speed,String name,int index){
        this.width = width;
        this.height = height;
        this.x = x;
        this.y = y;
        this.speed = speed;
        this.name = name;
        this.index = index;
    }


    public void move(){
        System.out.println("海洋对象移动了");
    }
    public void position(){
        System.out.println(name+index+"的坐标是"+y+","+x);
    }
    public boolean getDead(){
        return DEAD == 0;
    }
    public boolean getLive(){
        return LIVE == 1;
    }
    public abstract ImageIcon getImage();
    public void paintImage(Graphics g){
        if (getLive()){
            this.getImage().paintIcon(null,g,x,y);
        }
    }
}
